package com.helloUIBinder.client.widgets;


import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class HomePageWidget extends Composite {

    private static HomeBodyWidgetUiBinder uiBinder = GWT.create(HomeBodyWidgetUiBinder.class);

    interface HomeBodyWidgetUiBinder extends UiBinder<Widget, HomePageWidget> {
    }

    @UiField
    Anchor aboutLink;

    @UiField
    Anchor serviceLink;

    @UiField
    Anchor workLink;

    @UiField
    Anchor work1Link;


    @UiField
    Anchor work1LinkImage;


    public HomePageWidget() {
        initWidget(uiBinder.createAndBindUi(this));
        fooRunner();
    }

    @UiHandler("aboutLink")
    void onAboutWidgetClick(ClickEvent event) {
        AboutPageWidget aboutPageWidget = new AboutPageWidget();

        changeBodyTo(aboutPageWidget);
    }

    @UiHandler("serviceLink")
    void onServiceWidgetClick(ClickEvent event) {
        ServicePageWidget servicePageWidget = new ServicePageWidget();

        changeBodyTo(servicePageWidget);
    }


    @UiHandler("workLink")
    void onWorkWidgetClick(ClickEvent event) {
        WorkWidget workWidget = new WorkWidget();

        changeBodyTo(workWidget);
    }

    @UiHandler("work1Link")
    void onWork1WidgetClick(ClickEvent event) {
        WorkWidget workWidget = new WorkWidget();

        changeBodyTo(workWidget);
    }

    @UiHandler("work1LinkImage")
    void onWork1WidgetImageClick(ClickEvent event) {
        WorkWidget workWidget = new WorkWidget();

        changeBodyTo(workWidget);
    }

    private void changeBodyTo(Widget widget) {
        BodyContainerWidget currentBodyContainerWidget = (BodyContainerWidget) RootPanel.get().getWidget(1);
        currentBodyContainerWidget.getBodyContainer().remove(0);
        currentBodyContainerWidget.getBodyContainer().add(widget);
    }

    public static native void fooRunner() /*-{
        $doc.fooRunner();
    }-*/;
}
